package com.example.demo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.demo.dto.BoardroomAddDTO;
import com.example.demo.pojo.Boardroom;
import com.example.demo.dto.BoardroomUpdateDTO;
import com.example.demo.service.BoardroomService;
import com.example.demo.vo.BoardroomDevVO;
import com.example.demo.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjy
 * @since 2025-05-25
 */
@RestController
@RequestMapping("/boardroom")
@Api(tags = "会议室管理")
public class BoardroomController {
    @Autowired
    private BoardroomService boardroomService;

    @GetMapping("/queryBoardroom")
    @ApiOperation("查询会议室信息")
    public ResultVO<IPage<BoardroomDevVO>> queryBoardrooms(Integer id, String name, Integer page, Integer pageSize) throws Exception{
        IPage<BoardroomDevVO> result = boardroomService.queryBoardroomsWithDevices(id,name,page,pageSize);
        return ResultVO.success("查询成功",result);
    }

    @PostMapping("/addBoardroom")
    @ApiOperation("新增会议室及设备")
    public ResultVO<String> addBoardroom(@RequestBody BoardroomAddDTO dto) throws Exception{
        return boardroomService.addBoardroomWithDevices(dto);
    }

    @PostMapping("/updateBoardroom")
    @ApiOperation("更新会议室信息及设备")
    public ResultVO<String> updateBoardroom(@RequestBody BoardroomUpdateDTO dto) throws Exception{
        return boardroomService.updateBoardroomWithDevices(dto);
    }

    @PostMapping("/delBoardroom")
    @ApiOperation("删除会议室及设备")
    public ResultVO<String> delBoardroom(Integer id) throws Exception{
        return boardroomService.deleteBoardroomWithDevices(id);
    }

    @GetMapping("/query")
    @ApiOperation("带条件查询会议室信息")
    public ResultVO<IPage<BoardroomDevVO>> query(String date, String startTime, String endTime, Integer attendees, @RequestParam List<String> devices, Integer page, Integer pageSize) {
        IPage<BoardroomDevVO> result = boardroomService.searchBoardrooms(date, startTime, endTime, attendees, devices, page, pageSize);
        return ResultVO.success("查询成功", result);
    }

    @GetMapping("/getBoardroomIdByName")
    @ApiOperation("根据会议室名称查询会议室id")
    public ResultVO<Integer> getBoardroomIdByName(String name) {
        Integer id = boardroomService.getBoardroomIdByName(name);
        if (id == null) {
            return ResultVO.fail("未找到该会议室");
        }
        return ResultVO.success("查询成功",id);
    }

    //Hailin Gong start
    @GetMapping("/getBoardroomList")
    @ApiOperation("查询会议室列表")
    public ResultVO<IPage<Boardroom>> getBoardrooms(
            @RequestParam(required = false, defaultValue = "1") Integer page,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer type,
            @RequestParam(required = false) Integer minSeats,
            @RequestParam(required = false) Integer maxSeats) {

        IPage<Boardroom> result = boardroomService.getBoardrooms(page, pageSize, name, type, minSeats, maxSeats);
        return ResultVO.success("查询成功", result);
    }
    //Hailin Gong end
}
